\section*{Ubuntu Users}

If using Ubuntu 13.\-04 or greater, you can install the Key\-Cpp library and all dependencies using the following commands\-:

{\ttfamily sudo apt-\/add-\/repository ppa\-:jam4375/keycpp}

{\ttfamily sudo apt-\/get update}

{\ttfamily sudo apt-\/get install keycpp}

\section*{\label{_usage}%
Usage}

{\itshape This library uses features only available in the \href{https://en.wikipedia.org/wiki/C%2B%2B11}{\tt C++11 standard}. Y\-O\-U M\-U\-S\-T \href{http://gcc.gnu.org/projects/cxx0x.html}{\tt C\-O\-M\-P\-I\-L\-E} W\-I\-T\-H T\-H\-I\-S S\-T\-A\-N\-D\-A\-R\-D.}

Download the example code\-: \href{examples/example.cpp}{\tt example.\-cpp}. In the directory that you saved the file, execute the following commands to compile and run the example\-:

{\ttfamily g++ example.\-cpp -\/lkeycpp -\/lblas -\/llapack -\/std=c++11}

{\ttfamily ./example}

If everything is setup correctly, there should be no errors and the output should be the same as shown \href{#output}{\tt below}.

\section*{\label{_alt_install}%
Alternate Installation Instructions}

\subsection*{Download Source}

Download the complete source and documentation\-: \href{releases/keycpp-0.1.tar.gz}{\tt keycpp-\/0.\-1.\-tar.\-gz}.

If you want the most up-\/to-\/date version you can download the source by cloning the git repository from \href{http://code.google.com/p/keycpp/source/checkout}{\tt code.\-google.\-com/p/keycpp/}. It should be noted that the version on code.\-google.\-com may not be as stable as the compressed source file above.

After downloading the source, make sure you have the dependencies and follow the installation instructions below.

\subsection*{Dependencies}

Currently this project makes use of the \href{http://www.sourceforge.net/projects/kissfft/}{\tt Kiss F\-F\-T} and \href{http://code.google.com/p/gnuplot-cpp/}{\tt gnuplot-\/cpp} open source projects as well as the \href{http://www.netlib.org/lapack/}{\tt L\-A\-P\-A\-C\-K} libraries, \href{http://www.gnuplot.info/}{\tt Gnuplot} plotting program, and the \href{http://www.boost.org/doc/libs/1_54_0/libs/numeric/odeint/doc/html/index.html}{\tt Boost odeint} library. The sources from \href{http://www.sourceforge.net/projects/kissfft/}{\tt Kiss F\-F\-T} and \href{http://code.google.com/p/gnuplot-cpp/}{\tt gnuplot-\/cpp} have been incorporated into this project.

The {\itshape only} extra dependencies that you need on your system are the \href{http://www.netlib.org/lapack/}{\tt L\-A\-P\-A\-C\-K} libraries, \href{http://www.gnuplot.info/}{\tt Gnuplot}, and the \href{http://www.boost.org/doc/libs/1_54_0/libs/numeric/odeint/doc/html/index.html}{\tt Boost odeint} library.

\subsubsection*{Ubuntu (and various \href{https://wiki.ubuntu.com/UbuntuFlavors}{\tt flavors})}

{\itshape N\-O\-T\-E\-: For permformance reasons, use of Open\-B\-L\-A\-S/\-L\-A\-P\-A\-C\-K is preferred over the default versions.}

To acquire all the required dependencies you can execute the following commands\-:

{\ttfamily sudo apt-\/get install build-\/essential}

{\ttfamily sudo apt-\/get install libboost-\/dev}

{\ttfamily sudo apt-\/get install libopenblas-\/dev}

{\ttfamily sudo apt-\/get install liblapack-\/dev}

If using Ubuntu 13.\-04 or prior, you must download the source for \href{http://www.odeint.com}{\tt odeint} and copy the directory {\ttfamily ./boost/numeric/odeint} and file {\ttfamily ./boost/numeric/odeint.hpp} to {\ttfamily /usr/include/boost/numeric/}.

\subsection*{Installation}

To install Key\-Cpp onto your system first download the source \href{releases/keycpp-0.1.tar.gz}{\tt here} and extract to the directory of your choice\-:

{\ttfamily tar -\/zxvf keycpp-\/0.\-1.\-tar.\-gz}

{\ttfamily cd ./keycpp}

The following command will compile the Key\-Cpp library and provide links to the library and header files in Ubuntu's default location\-:

{\ttfamily sudo ./\-I\-N\-S\-T\-A\-L\-L}

To uninstall the Key\-Cpp library, use the following command\-:

{\ttfamily sudo ./\-U\-N\-I\-N\-S\-T\-A\-L\-L}

\subsubsection*{Other Operating Systems}

This library has not been tested on operating systems other than Ubuntu yet. You should be able to get this library working on other linux distributions or O\-S X with slight modifications to the procedures above. Windows users may have a harder time getting this library to compile. For all operating systems, first make sure that you have all of the dependencies.

\section*{Intel M\-K\-L}

For Intel processors, the \href{http://software.intel.com/en-us/intel-mkl}{\tt Intel M\-K\-L} libraries provide the best performance. If you choose to use Intel's M\-K\-L libraries, the necessary compiler flags are\-:

{\ttfamily g++ example.\-cpp -\/lkeycpp -\/\-L/\$(M\-K\-L\-R\-O\-O\-T)/lib/intel64 -\/lmkl\-\_\-rt -\/std=c++11}

or using the Intel C++ compiler\-:

{\ttfamily icc example.\-cpp -\/lkeycpp -\/\-L/\$(M\-K\-L\-R\-O\-O\-T)/lib/intel64 -\/lmkl\-\_\-rt -\/std=c++11}

If writing parallel applications, especially using Open\-M\-P, it is highly recommended to use the Inter C++ compiler. Using {\ttfamily g++}, Open\-M\-P, and Intel M\-K\-L together sometimes produces undefined behavior.

\section*{\label{_example}%
Example Code}

{\bfseries {\ttfamily example.\-cpp}} 
\begin{DoxyCodeInclude}
1 \textcolor{preprocessor}{#include <iostream>}
2 \textcolor{preprocessor}{#include <keycpp/keycpp.h>}
3 \textcolor{keyword}{using namespace }keycpp;
4 
5 \textcolor{comment}{// Define a class for our ordinary differential equation that we will use later:}
6 \textcolor{keyword}{class }\hyperlink{class_ode_class}{OdeClass}
7 \{
8     \textcolor{keyword}{public}:
9         \textcolor{keywordtype}{void} operator()(\textcolor{keyword}{const} \hyperlink{classkeycpp_1_1matrix}{matrix<double>} &y,
10                         \hyperlink{classkeycpp_1_1matrix}{matrix<double>} &dy,
11                         \textcolor{keyword}{const} \textcolor{keywordtype}{double})
12         \{
13             dy(0) = y(1)*y(2);
14             dy(1) = -y(0)*y(2);
15             dy(2) = -0.51*y(0)*y(1);
16         \}
17 \};
18 
19 \textcolor{keywordtype}{int} main()
20 \{
21     \textcolor{comment}{// First, lets create some data: y1 = t^2 and y2 = t^3}
22     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} t = linspace(-2.0,2.0,100);
23     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} y1 = \hyperlink{namespacekeycpp_a23a0fd48168263aad7f77f1769dc2f2a}{times}(t,t);
24     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} y2 = \hyperlink{namespacekeycpp_a23a0fd48168263aad7f77f1769dc2f2a}{times}(t,\hyperlink{namespacekeycpp_a23a0fd48168263aad7f77f1769dc2f2a}{times}(t,t));
25 
26     \textcolor{comment}{// Now, lets plot the data we just created:}
27     \hyperlink{classkeycpp_1_1_figure}{Figure} h1;
28     h1.plot(t,y1,\textcolor{stringliteral}{"b-"},\textcolor{stringliteral}{"linewidth"},2);
29     h1.hold\_on();
30     h1.plot(t,y2,\textcolor{stringliteral}{"r--"},\textcolor{stringliteral}{"linewidth"},2);
31     h1.grid\_on();
32     h1.xlabel(\textcolor{stringliteral}{"t"});
33     h1.ylabel(\textcolor{stringliteral}{"y"});
34     h1.legend(\{\textcolor{stringliteral}{"y1 = t^2"},\textcolor{stringliteral}{"y2 = t^3"}\});
35     set(h1,\textcolor{stringliteral}{"fontsize"},14);
36 
37     \textcolor{comment}{// This is how to solve linear equations of the form Ax = b:}
38     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} A = \{\{1.0, 2.0\},
39                         \{1.0,-1.0\}\};
40     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} b = \{1.1,
41                         2.1\};
42     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} x = linsolve(A,\hyperlink{namespacekeycpp_a7fd5ce0385e9cc7bed5b44ed8475e8aa}{transpose}(b));
43     \textcolor{comment}{// Print the result to the screen:}
44     \hyperlink{namespacekeycpp_af4a2245da139cf6cf2e03426476b3b88}{disp}(x);
45 
46     \textcolor{comment}{// Now lets do something a little more complicated, solve an}
47     \textcolor{comment}{// ordinary differential equation (ODE):}
48     \textcolor{comment}{// y(1)' = y(2)*y(3);}
49     \textcolor{comment}{// y(2)' = -y(1)*y(3);}
50     \textcolor{comment}{// y(3)' = 0.51*y(1)*y(2);}
51     \textcolor{comment}{// With initial conditions at t = 0: y(1) = 0; y(2) = 1; y(3) = 1;}
52     \hyperlink{class_ode_class}{OdeClass} myOde;
53     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} t2 = linspace(0.0,12.0,100);
54     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} ICs = \{0.0, 1.0, 1.0\};
55     \hyperlink{classkeycpp_1_1matrix}{matrix<double>} y = ode45(myOde, t2, ICs);
56     
57     \textcolor{comment}{// Now that we have solved the ODE, lets plot the results:}
58     \hyperlink{classkeycpp_1_1_figure}{Figure} h2;
59     h2.plot(t2,y.col(0),\textcolor{stringliteral}{"-"});
60     h2.hold\_on();
61     h2.plot(t2,y.col(1),\textcolor{stringliteral}{"-."});
62     h2.plot(t2,y.col(2),\textcolor{stringliteral}{"x"});
63     h2.xlabel(\textcolor{stringliteral}{"t"});
64     h2.ylabel(\textcolor{stringliteral}{"y"});
65     set(h2,\textcolor{stringliteral}{"fontsize"},14);
66     h2.title(\textcolor{stringliteral}{"ODE Solution"});
67 
68     \textcolor{keywordflow}{return} 0;
69 \}
\end{DoxyCodeInclude}
 \par
 \label{_output}%
 {\bfseries {\ttfamily Text} Output} 
\begin{DoxyCodeInclude}
\end{DoxyCodeInclude}
 \par
 {\bfseries {\ttfamily Plot} Output}  \par
  \par


\section*{M\-A\-T\-L\-A\-B/\-Octave to Key\-Cpp Conversion Chart}

Although the goal of this library is to offer a C++ interface similar in syntax to M\-A\-T\-L\-A\-B/\-Octave, there are some minor differences. The goal of this document is to provide a conversion chart for some of the most commonly used features.

Note\-: You can omit the {\ttfamily keycpp\-:\-:} prefix from the following commands by placing {\ttfamily using namespace keycpp;} in the same scope. This shortcut should be used with care as collisions with other libraries are possible.

\begin{TabularC}{3}
\hline
\rowcolor{lightgray}{\bf {\itshape M\-A\-T\-L\-A\-B/\-Octave} }&{\bf {\itshape Key\-Cpp} }&{\bf Notes  }\\\cline{1-3}
{\ttfamily A(1,1)} &{\ttfamily A(0,0);} &Indexing starts at 0 in Key\-Cpp \\\cline{1-3}
{\ttfamily A(\-N,\-N)} &{\ttfamily A(N-\/1,N-\/1);} &\\\cline{1-3}
{\ttfamily size(\-A,1)} &{\ttfamily keycpp\-::size(\-A,1);} &\\\cline{1-3}
{\ttfamily size(\-A,2)} &{\ttfamily keycpp\-::size(\-A,2);} &\\\cline{1-3}
{\ttfamily A(\-:,k)} &{\ttfamily A.\-get\-Col(k-\/1);} &C++ restricts the use of {\ttfamily \-:} \\\cline{1-3}
{\ttfamily A(k,\-:)} &{\ttfamily A.\-get\-Row(k-\/1);} &\\\cline{1-3}
{\ttfamily A.'} &{\ttfamily keycpp\-::transpose(\-A);} &C++ does not allow overloading {\ttfamily .'} \\\cline{1-3}
{\ttfamily A'} &{\ttfamily keycpp\-::ctranspose(\-A);} &C++ does not allow overloading {\ttfamily '} \\\cline{1-3}
{\ttfamily A = zeros(m,n)} &{\ttfamily \hyperlink{classkeycpp_1_1matrix}{keycpp\-::matrix}$<$double$>$ A = \hyperlink{namespacekeycpp_a5699c522088657287bf0ac01173b716c}{keycpp\-::zeros}$<$double$>$(m,n);} &or more simply\-: {\ttfamily \hyperlink{classkeycpp_1_1matrix}{keycpp\-::matrix}$<$double$>$ A(m,n);} \\\cline{1-3}
{\ttfamily A = ones(m,n)} &{\ttfamily \hyperlink{classkeycpp_1_1matrix}{keycpp\-::matrix}$<$double$>$ A = \hyperlink{namespacekeycpp_a388f91a0ccf34978ef9403ccd0c680bf}{keycpp\-::ones}$<$double$>$(m,n);} &\\\cline{1-3}
{\ttfamily A.$\ast$\-B} &{\ttfamily keycpp\-::times(\-A,\-B);} &C++ does not allow overloading {\ttfamily .$\ast$} or {\ttfamily ./} \\\cline{1-3}
{\ttfamily A./\-B} &{\ttfamily keycpp\-::rdivide(\-A,\-B);} &\\\cline{1-3}
{\ttfamily A\textbackslash{}b} &{\ttfamily keycpp\-::linsolve(\-A,b);} &{\ttfamily b} is a vector \\\cline{1-3}
{\ttfamily \mbox{[}V, D\mbox{]} = eig(\-A,\-B)} &{\ttfamily std\-::vector$<$std\-::complex$<$double$>$$>$ d = keycpp\-::eig(\-A,\-B,\&\-V);} &Non-\/\-Hermitian generalized eigenvalue/eigenvector solver uses L\-A\-P\-A\-C\-K. \\\cline{1-3}
{\ttfamily x = linspace(0,10,\-N\-\_\-x)} &{\ttfamily std\-::vector$<$double$>$ x = keycpp\-::linspace(0.\-0,10.\-0,N\-\_\-x);} &\\\cline{1-3}
{\ttfamily x = logspace(1,3,\-N\-\_\-x)} &{\ttfamily std\-::vector$<$double$>$ x = \hyperlink{namespacekeycpp_a28626d0ffc4ecda3f9bc6e7b0f4fc4d2}{keycpp\-::logspace}(1.\-0,3.\-0,N\-\_\-x);} &{\ttfamily 10 $<$= x $<$= 1000} \\\cline{1-3}
{\ttfamily A = diag(\mbox{[}a1, a2, a3\mbox{]})} &{\ttfamily \hyperlink{classkeycpp_1_1matrix}{keycpp\-::matrix}$<$double$>$ A = keycpp\-::diag(\{a1, a2, a3\});} &{\ttfamily a1}, {\ttfamily a2}, and {\ttfamily a3} are scalar elements of {\ttfamily A} \\\cline{1-3}
{\ttfamily A = \mbox{[}\mbox{[}a1, a2\mbox{]}; \mbox{[}a3, a4\mbox{]}\mbox{]}} &{\ttfamily \hyperlink{classkeycpp_1_1matrix}{keycpp\-::matrix}$<$double$>$ A = \{\{a1, a2\}, \{a3, a4\}\};} &\\\cline{1-3}
\end{TabularC}
